<?php //Pagina principala a site-ului
require_once("/includes/config.php");
$page_title = "Fifaonline.ro | Campionate fifa virtuale | Stiri sportive";
include_once("/includes/head.php");
?>
<body>
<?php
include_once("/includes/header.php");
?>
<!--body start -->
<div id="body">
<!--left panel start -->
<?php
include_once("/includes/sidea.php");
?>
<!--left panel end -->
<!--right panel start -->
<div id="right">
<p><b>Recuperarea parolei</b></p>
<hr  color='#CCCCCC' width='500px' align='left' />
<?php
if(isset($_POST["submitted"]))
{
	require_once("mysql_connect.php");
	if(empty($_POST["email"]))
	{
		$uid = FALSE;
		echo "<p><font color='red'>Nu ai introdus email-ul</font></p>";
	}
	else
	{
		$query = "SELECT user_id FROM users WHERE email='" . escape_data($_POST['email']) .'"';
		$result = mysql_query($query) or trigger_error("Query: $query\n<br> MySQL Error: " .mysql_error());
		if(mysql_num_rows($result) == 1)
		{
			//Regaseste identificatorul utilizatorului
			list($uid) = mysql_fetch_array($result, MYSQL_NUM);
		}
		else
		{
			echo "<p><font color='red'>Aceasta adresa de email nu exista in baza de date</font></p>";
			$uid = FALSE;
		}
	}

	if($uid)
	{
		//Creeaza o parola noua
		$p = substr(md5(uniqid(rand(),1), 3, 10));
		//Realizeaza interogarea
		$query = "UPDATE users SET password=SHA('$p') WHERE user_id=$uid";
		$result = mysql_query($query) or trigger_error("Query: $query\n <br> MySQL Error: " .mysql_error());
		if(mysql_affected_rows() == 1)
		{
			//Trimite mesaj
			$body = "Parola ta de autentificare la site-ul fifaonline.ro a fost temporar schimbata cu '$p'. Conecteaza-te folosind aceasta parola si email-ul tau. Dupa autentificare poti sa iti schimbi parola cu ceva mai familiar.";
			mail($_POST["email"], "Parola temporara", $body, 'From: admin@fifaonline.ro');
			echo "<h3>Parola ta a fost schimbata. Vei primi o parola noua, temporara pe adresa ta de email cu care vei fi inregistrat. Dupa conectarea cu parola respectiva vei putea sa o schimbi accesand link-ul 'Schimba parola'</h3>";
			mysql_close();
			exit();
		}
		else
		{
			echo "<p><font color='red'>Parola ta nu a putut fi schimbata datorita unor probleme de sistem. Ne pare rau.</font></p>";
		}
	}
	else
	{//a esuat testul de validare
		echo "<p><font color='red'>Mai incearca o data</font></p>";
	}
	mysql_close();
}
?>
<p class="text2">Introdu email-ul pentru a schimba parola.</p>
<form action="forgot_password.php" method="post">
<fieldset>
<center>
<table>
<tr><td><p class="text2">Email: </p></td><td><input type="text" name="email" size="20" value="<?php if(isset($_POST['email'])) echo $_POST['email']?>"></td></tr>
</table>
<br>
<input type="submit" name="submit" value="Reseteaza parola">
</center>
<input type="hidden" name="submitted" value="TRUE">
</fieldset>
<br>
</form>
</div>
<!--right panel end -->
<br class="spacer" />
</div>
<!--body end -->
<!--footer start -->
<?php
include_once("/includes/footer.php");
?>
<!--footer end -->
</body>
</html>